package com.java.demo;

import java.util.Scanner;

public class computer {
    public static void main(String[] args) {
        // 目标：实现简易计算器
        // 1.键盘录入两个整数
        Scanner sc = new Scanner(System.in);
        System.out.println("input number1:");
        double num1 = sc.nextDouble();

        System.out.println("input number2:");
        double num2 = sc.nextDouble();

        System.out.println("input operator(+, -, *, /");
        String operator = sc.next(); // "+"

        // 2.把这个数据交给一个独立的计算方法，然后计算出来
        double result = calc(num1, num2, operator);
        System.out.println(result);

        
    }

    public static double calc(double num1, double num2, String operator) {
        double result = 0;
        switch (operator) {
            case "+":
                result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                result = num1 / num2;
                break;
            default:
                System.out.println("error");
                break;

        }
        return result;
    }
}
